import sys
import traceback

command_list: dict = {}


def register(command: str, process):
    command_list[command] = process


def unregister(command: str):
    command_list.pop(command)


def command(command: list):
    if command[0] == "":
        return None
    elif command[0] in command_list.keys():
        try:
            if command[1:]:
                return command_list[command[0]](command[1:])
            else:
                return command_list[command[0]]()
        except Exception as e:
            traceback.print_exc()
            return None
    else:
        return "未知指令"
